package com.liugui;

/**
 * @ClassName: DaemonDemo
 * @Author: liugui
 * @Date: 2021-05-19 15:55
 **/
public class DaemonDemo {

    public static void main(String[] args) {
        MyThread5 m5 = new MyThread5();
        Thread t5 = new Thread(m5);
        t5.setDaemon(true);// 设置为后台线程 或称之为守护线程
        t5.start();
        System.out.println("主线程结束");
    }

}

class MyThread5 implements Runnable {
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "在后台执行");
        }
    }
}
